<template>
  <div class="page" style="">
    <div class="print_title">借款申请详情 · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px; position: relative;">
      <vue-qr class="codeImg" v-if="formData.bpmStatus == '3'" ref="qrCodeImg" :text="qrCodeText"></vue-qr>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposer_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposerDeptId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">关联项目:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col> -->

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请公司:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.companyId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">使用日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.useDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">借款所属团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{
              formData.teamId_dictText?formData.teamId_dictText:formData.teamId }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.teamYear=='2023'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">费用所属年度:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.teamYear }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">是否关联项目:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.isFree_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >关联项目:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col> -->
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectCode }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">业绩归属年度:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectYear }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">借款方式:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.borrowMode_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">借款用途:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.purpose_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">归还日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.returnDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">借款金额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.amount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">借款说明:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.borrowExplain }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <p class="title" style="margin-top: 18px;" v-if="formData.borrowMode == '2'">收款信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;" v-if="formData.borrowMode == '2'">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">领款人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payee_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">开户银行:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.bankName }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">银行账户:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.bankAccountNo }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" title="附件信息" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import address from '@/components/AddressChoice/address.js'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import VueQr from 'vue-qr'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor,
    VueQr
  },
  data() {
    return {
      qrCode: null,
      address,
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      columns: [
      {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 45,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目名称',
          align: 'center',
          width: 75,
          dataIndex: 'projectId',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['projectId'], text + '')
            }
          }
        },
        {
          title: '项目承接人',
          align: 'center',
          width: 55,
          dataIndex: 'projectUndertaker',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['projectUndertaker'], text + '')
            }
          }
        },
        {
          title: '业绩归属年度',
          align: 'center',
          width: 55,
          dataIndex: 'projectYear',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['projectYear'], text + '')
            }
          }
        },
        {
          title: '经营团队',
          align: 'center',
          width: 65,
          dataIndex: 'busiTeamId',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['busiTeamId'], text + '')
            }
          }
        },
        {
          title: '项目合同',
          align: 'center',
          width: 85,
          dataIndex: 'contractNo',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['contractNo'], text + '')
            }
          }
        },
        {
          title: '合同款项',
          align: 'center',
          width: 65,
          dataIndex: 'contractMoneyItemId',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['contractMoneyItemId'], text + '')
            }
          }
        },
        {
          title: '应收款(元)',
          width: 55,
          align: 'center',
          dataIndex: 'receivables'
        },
        {
          title: '已收款(元)',
          width: 55,
          align: 'center',
          dataIndex: 'collectedMoney'
        },
        {
          title: '本次收款(元)',
          width: 65,
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '未回款(元)',
          width: 55,
          align: 'center',
          dataIndex: 'unreturnedMoney'
        }
			],
			dataHistorySource: [], // 流程列表
			url: {
				list: '/api/erp/finance/repayment/erpFinanceRepaymentSlipDetail/allList', // 物料明细列表
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
			purchaseFile: [] // 附件
    };
  },
	watch: {
		formData: {
			async handler (val) {
				if (val) {
					this.list()
					// this.getHistoryList()
          this.initDictConfig() // 字典值
					if (val.attachments) {
						this.purchaseFile = val.attachments.split(',')
					}
				}
			},
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		}
	},
  computed: {
    qrCodeText () {
      return JSON.stringify({
        billNo: this.formData.billNo,
        billType: '5',
      })
    }
  },
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},

    async initDictConfig() {
      initDictOptions('erp_omc_team_manager,alias_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'busiTeamId', res.result)
          }
        })
        // initDictOptions('tdnd_type').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'teamYear', res.result)
        //   }
        // })
        initDictOptions('yjgsnd').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectYear', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
        initDictOptions('erp_omc_contract_manager_final,htmc,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'contractNo', res.result)
          }
        })
        initDictOptions('erp_employee_file,name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectUndertaker', res.result)
          }
        })
        // 合同款项
        initDictOptions('erp_progress_payment_node,node_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'contractMoneyItemId', res.result)
          }
        })
        // 项目进度
        // initDictOptions('erp_progress_contract_node,node_name,id').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'projectPlan', res.result)
        //   }
        // })
    },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
        billId: this.formData.id
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			console.log('record, index', record, index)
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    },

    getAddress (text) {
      if (!text) {
        return false
      }
      var areaList = text.split(',')
      var areaText = ''
      this.address.map(value => {
        if (areaList[0] && areaList[0] == value.code) {
          areaText = areaText + value.name + '/'
          if (value && value.children && value.children.length) {
            value.children.map(val => {
              if (areaList[1] && areaList[1] == val.code) {
                areaText = areaText + val.name + '/'

                if (val && val.children && val.children.length) {
                  val.children.map(va => {
                    if (areaList[2] && areaList[2] == va.code) {
                      areaText = areaText + va.name
                    }
                  })
                }
              }
            })
          }
        }
      })
      return areaText
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
.content{
  font-size: 13px;
}
.codeImg{
  width: 56px;
  height: 56px;
  background: #ccc;
  position: absolute;
  right: 0px;
  top: 0px;
}
</style>
